package top.shiyiri.servlet2;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Aunean
 * @date 2022/1/27 15:25
 */
public class Servlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求的参数查看
        String username = request.getParameter("username");
        System.out.println("在Servlet1中查看参数：" + username);

        //在request域中设置一个值，并传递到Servlet2去查看
        request.setAttribute("key", "Servlet1中的值");

        /*
        请求转发必须要以斜杆开头， / 斜杆表示地址为 http://ip:port/工程名/
         */
//        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/servlet2");
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/WEB-INF/a.html");

        //传递
        requestDispatcher.forward(request, response);
    }
}
